extends Node

signal released(pos)

var parent
@export var ReturnToStart : bool = true

var pos_locked
var touch_pos
var entered = false
var init_pos : Vector2

func _ready():
	parent = self.get_parent()
	init_pos = parent.position
	parent.connect("gui_input",self._on_gui_input)

func _on_gui_input(event):
	if event is InputEventScreenDrag:
		if !pos_locked:
			if touch_pos!=Vector2.ZERO:
				parent.global_position += (event.position-touch_pos)*parent.scale

			
	if event is InputEventScreenTouch:
		touch_pos = event.position
			
		if !event.pressed:
			emit_signal("released", parent.position)
			if !entered:
				if ReturnToStart:
					parent.position = init_pos
